package com.lesso.lpq.sunflower.core;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import com.lesso.lpq.sunflower.model.BaseModel;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * MyMetaObjectHandler
 *
 * @author zqz
 * @since 2025-07-03
 */
@Component
public class MyMetaObjectHandler extends MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object object = metaObject.getOriginalObject();
        if (object instanceof BaseModel) {
            ((BaseModel<?>) object).setCreateTime(LocalDateTime.now());
        }
        this.updateFill(metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object object = metaObject.getOriginalObject();
        if (object instanceof BaseModel) {
            ((BaseModel<?>) object).setUpdateTime(LocalDateTime.now());
        }
    }
}
